import colors from 'colors'
import { time } from "../utils/day.utc";
import { Request, Response } from "express";

/**
 * ### 全局请求处理器
 */

export const globalReqProcMidd = (req: Request, res: Response, next: any) => {

  // 打印请求日志
  console.log(colors.bold(`\n>>>>>>> ${req.ip} 接口请求：`).bgBlue);
  console.log(`\n======${time().format('YYYY-MM-DD HH:mm:ss')}======\n`);
  console.log(`请求接口: ${req.path}`);
  console.log(`请求方式: ${req.method}`);
  console.log(`\nQuery 参数:`);
  console.log(req.query);
  console.log(`\nBody 参数:`);
  console.log(req.body);
  console.log(`\nParams 参数:`);
  console.log(req.params);
  console.log(`\n======${time().format('YYYY-MM-DD HH:mm:ss')}======\n`);

  next()
}